home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
ai
/
dynamic.pro
< prev
next >
Wrap
Text File
|
1990-05-19
|
6KB
|
217 lines
/* USING TURBO PROLOG TO FORMULATE
DYNAMIC OPTIMIZATION MODELS
JULY 12, 1986
GARRY J. VASS [72307,3311] (c)
INTRODUCTION
------------
Dynamic optimization is an operations research/
management science technique for expressing small
to medium scale problems with a single, deterministic
optimum value. Dynamic optimization models are
frequently characterized by recursive formulations,
making them especially interesting as PROLOG exercises.
The purpose of this file is to illustrate my findings
in this area. Comments, suggestions, or efficiency
improvements are welcome.
The problem is taken from Chapter Eight of "PRINCIPLES
OF OPERATIONS RESEARCH", (Second Edition) by Harvey M.
Wagner. Where possible, the program notation is
consistent with the text. Please refer to this
text for a complete, lucid, and articulate
presentation of the problem.
PROBLEM
-------
Mark Off is planning a trip from New York (Point 1) to
San Francisco (Point 10), and concludes that he
is faced with a classical network routing problem.
Each of the available routes will require four
legs (or three intermediate stopping places).
From each stopping place, (or node),
Mark can take one, two, or sometimes
three different "stages" with different costs
according to the table below (a map/graphic
is better, but the table will have to do):
From Point To Point Cost
---------- -------- ----
1 2 2
1 4 1
1 3 5
2 5 10
2 6 12
3 5 5
3 6 10
3 7 7
4 6 15
4 7 13
5 8 7
5 9 5
6 8 3
6 9 4
7 8 7
7 9 1
8 10 1
9 10 4
With limited resources, Mark Off elects to
locate the "optimal routing" (i.e. the one
with the minimum total cost).
ANALYSIS
--------
The network itself is expressed with the
cij predicate, appearing in Wagner as the
"Cost" to go from "Point I" to "Point J".
To simplify the problem, the remaining
decisions are added to the predicate.
For example,
cij(3,4,6,15)
means that at Point 4, there are three
decisions to be made before the end is
reached and it is possible to go to Point
6 for a cost of 15.
cij(1,9,10,4)
means that at Point 9, there is one decision
yet to be made and it is possible to go from
Point 9 to Point 10 for a cost of 4.
Next, there is the "f" predicate which uses
six parameters: remaining decisions, current
state (or "node", location, point, etc),
a running cost total (intermediate), the
final cost total, a running route list
(intermediate), and a final route list.
The important ones here are the remaining
decisions, the current state, and the running
cost total. The others are for cosmetics.
f(0,10,T,....) is a terminal condition, meaning
that there are 0 decisions remaining and that
Mark is in Point 10 and has paid out T.
*/
nowarnings
domains
list = integer*
predicates
optimal_route
integer_list_minimum(integer, list, integer)
/* start value, list, returned value */
cij(integer, integer, integer, integer)
/* remaining decisions, pointi, pointj, cost */
f(integer, integer,integer,integer,list,list)
/* remaining decisions, pointi, cost */
append(list,list,list)
goal
optimal_route.
clauses
optimal_route if
/* collect all possible costs going from point 1 to point 10
and put them into a list called Costlist. */
findall(Cost,f(4, Nodes, 0, Cost, Running_route, Final_route),Costlist) and
/* find the minimum value in Costlist and put it in
the variable Minimum. Assume that no cost will be
greater than 9999. */
integer_list_minimum(9999 ,Costlist, Minimum) and
/* go back and find a solution having a total cost
equal to the variable Minimum. Put the nodes
into the list variable Optimal_list. */
f(4, Anynodes, 0, Minimum, Anylist, Optimal_list) and
/* write out the nodes in the optimal route and beg
everyone's forgiveness for not bothering to reverse
the list first */
nl and
write("Nodes in least cost route are: ",Optimal_list) and
/* write out the minimum cost associated with the above list. */
nl and
write("Minimum cost = ",Minimum).
/* network predicates */
cij(1,8,10,1).
cij(1,9,10,4).
cij(2,5,8,7).
cij(2,6,8,3).
cij(2,7,8,7).
cij(2,5,9,5).
cij(2,6,9,4).
cij(2,7,9,1).
cij(3,2,5,10).
cij(3,2,6,12).
cij(3,3,5,5).
cij(3,3,6,10).
cij(3,3,7,7).
cij(3,4,6,15).
cij(3,4,7,13).
cij(4,1,2,2).
cij(4,1,3,5).
cij(4,1,4,1).
/* if there are zero decisions left to be made
and we are in point 10, then we must be done. */
f(0, 10, Runningmiles, Totalmiles, Routelist, Finallist) if
Totalmiles = Runningmiles and
Finallist = Routelist.
/* if there are other than zero decisions left to
be made and we are in state "State", then find
the next state in the network and keep track of
the miles. Then see what happens in the next
state with one less decision to be made. */
f(Remaining, State, Runningmiles, Totalmiles, Routelist, Finallist) if
cij(Remaining, State, Nextstate, Miles) and
append([State], Routelist, Newroutelist) and
Newremaining = Remaining - 1 and
Newmiles = Runningmiles + Miles and
f(Newremaining, Nextstate, Newmiles, Totalmiles, Newroutelist, Finallist).
/* general purpose list predicates */
append([],L,L).
append([X|L1], L2, [X|L3]) if append(L1, L2, L3).
integer_list_minimum(X,[],M) if M = X.
integer_list_minimum(X, [H|T],M) if
H <= X and
integer_list_minimum(H,T,M).
integer_list_minimum(X, [H|T],M) if
integer_list_minimum(X,T,M).
ease refer to this
text for a complete, lucid, and articulate
presentation o